package com.kamistoat.meimeimall.meimeimallorder.dao;

import com.kamistoat.meimeimall.common.annotation.AutoFillCreateTime;
import com.kamistoat.meimeimall.meimeimallorder.entity.OrderEntity;
import com.kamistoat.meimeimall.meimeimallorder.enums.OrderStatusEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 订单
 *
 * @author kamistoat
 * @email linjianshanke@163.com
 * @date 2021-09-12 16:42:29
 */
@Mapper
public interface OrderDao {
    /**
     * 更新状态
     *
     * @return 操作成功行数
     */
    Long changeOrderStatus(@Param("orderSn") String orderSn,
                           @Param("fromStatus") Integer fromStatus,
                           @Param("toStatus") Integer toStatus);

    /**
     * 查询用户所有订单，并按时间倒叙排列
     */
    List<OrderEntity> selectAllOrderByMemberId(@Param("memberId") Long memberId);

    /**
     * 一次完成 订单-子订单-商品 的join查询
     *
     * @param memberId
     */
    void selectOrderSubOrderItemOnce(Long memberId);

    /**
     * 根据memberId、orderSn、状态
     *
     * @return
     */
    OrderEntity selectByMemberIdAndOrderSnAndStatus(@Param("member_id") Long memberId,
                                                    @Param("order_sn") String orderSN,
                                                    @Param("status") OrderStatusEnum status);

    /**
     * insert
     *
     * @param newCreateOrder
     */
    @AutoFillCreateTime
    Long insert(@Param("entity") OrderEntity newCreateOrder);

    /**
     * 逻辑删除
     */
    Long logicDeleteByOrderSn(@Param("orderSn") String orderSn);
}
